﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

namespace Maticsoft.Web.sysMan
{
    public partial class ModifyMost : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int mostId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(mostId);
                }
            }
        }

        private void ShowInfo(int mostId)
        {
            Maticsoft.BLL.mostInfo bll = new Maticsoft.BLL.mostInfo();
            Maticsoft.Model.mostInfo model = bll.GetModel(mostId);
            this.lblmostId.Text = model.mostId.ToString();
            this.txtmtitle.Text = model.mtitle;
            this.txtmA.Text = model.mA;
            this.txtmB.Text = model.mB;
            this.txtmC.Text = model.mC;
            this.txtmD.Text = model.mD;
            this.txtmkey.Text = model.mkey;
            this.txtmscore.Text = model.mscore.ToString();
            this.txtstuType.Text = model.stuType;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtmtitle.Text.Trim().Length == 0)
            {
                strErr += "多选题题目内容不能为空！\\n";
            }
            if (this.txtmA.Text.Trim().Length == 0)
            {
                strErr += "A不能为空！\\n";
            }
            if (this.txtmB.Text.Trim().Length == 0)
            {
                strErr += "B不能为空！\\n";
            }
            if (this.txtmC.Text.Trim().Length == 0)
            {
                strErr += "C不能为空！\\n";
            }
            if (this.txtmD.Text.Trim().Length == 0)
            {
                strErr += "D不能为空！\\n";
            }
            if (this.txtmkey.Text.Trim().Length == 0)
            {
                strErr += "答案不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtmscore.Text))
            {
                strErr += "分值格式错误！\\n";
            }
            if (this.txtstuType.Text.Trim().Length == 0)
            {
                strErr += "stuType不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int mostId = int.Parse(this.lblmostId.Text);
            string mtitle = this.txtmtitle.Text;
            string mA = this.txtmA.Text;
            string mB = this.txtmB.Text;
            string mC = this.txtmC.Text;
            string mD = this.txtmD.Text;
            string mkey = this.txtmkey.Text;
            decimal mscore = decimal.Parse(this.txtmscore.Text);
            string stuType = this.txtstuType.Text;


            Maticsoft.Model.mostInfo model = new Maticsoft.Model.mostInfo();
            model.mostId = mostId;
            model.mtitle = mtitle;
            model.mA = mA;
            model.mB = mB;
            model.mC = mC;
            model.mD = mD;
            model.mkey = mkey;
            model.mscore = mscore;
            model.stuType = stuType;

            Maticsoft.BLL.mostInfo bll = new Maticsoft.BLL.mostInfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "ListMost.aspx");

        }
    }
}